home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / criterrc.zip / CRITERR.ASM < prev    next >
Assembly Source File  |  1991-02-17  |  9KB  |  301 lines

  1.         TITLE    CRITERR.ASM
  2.         SUBTTL    TRAP CRITICAL ERRORS FROM W/IN C
  3.  
  4.         IFDEF ??version            ;TASM
  5.           %NOCONDS
  6.         ELSE                            ;MASM
  7.           .SFCOND            ;DONT SHOW FALSE CONDITIONALS
  8.         ENDIF
  9.  
  10. ; MODULE CRITERR.ASM
  11. ; JANUARY 1991
  12. ; PETER HYMAN (609) 799-2638
  13. ; 148 TENNYSON DRIVE
  14. ; PLAINSBORO, NJ  08536
  15.  
  16. ; MODIFIED 2/16/91 SEE NOTES AT END OF SOURCE FOR DESCRIPTION OF CHANGES
  17.  
  18. ;;;;; TWO FUNCTIONS ;;;;;
  19.  
  20. ; FUNCTION NAME:  CRITERR( ONOFF )
  21. ; INPUTS 1 = TRAP CRITICAL ERRORS, 0 TURN OFF TRAP
  22. ; RETURNS 0 IF SUCCESSFUL, 1 IF ALREADY INSTALLED
  23.  
  24. ; FUNCTION NAME:  CLRCRITERR( )
  25. ; CLEAR CRITICAL ERROR VARIABLES
  26.  
  27. ; ON CRITICAL ERRORS, INT 24H HANDLER WILL RETURN AN IGNORE CODE TO DOS
  28. ; IF VERSION < 3, OR A FAIL CODE FOR DOS >= 3
  29. ; IF VERSION >= 3, DOS FUNCTION 59H IS CALLED ALSO, AND EXTENDED ERROR
  30. ; INFO IS ALSO PUT INTO STRUCTURE
  31.  
  32. ;;;;; USES SIMPLIFIED SEGMENT DIRECTIVES.  ASSEMBLE WITH I8086S, M, C OR L
  33. ;;;;; DEFINED
  34.  
  35. ;;;;; ASSEMBLE AS MASM/TASM /mx /dI8086[S|M|C|L] criterr;
  36. ;;;;; TURBO ASSEMBLER YIELDS SMALLER CODE WITH /Q OPTION
  37.  
  38.     IFDEF I8086S
  39.         .MODEL    SMALL
  40.         p equ 4            ; p is offset into stack for args
  41.         SCODE EQU 1
  42.     ENDIF
  43.     IFDEF I8086M
  44.         .MODEL    MEDIUM
  45.         p equ 6
  46.         LCODE equ 1
  47.     ENDIF
  48.     IFDEF I8086C
  49.         .MODEL    COMPACT
  50.         p equ 4
  51.         SCODE EQU 1
  52.         LDATA EQU 1
  53.     ENDIF
  54.     IFDEF I8086L
  55.         .MODEL    LARGE
  56.         p equ 6
  57.         LCODE EQU 1
  58.         LDATA EQU 1
  59.     ENDIF
  60.     IFNDEF I8086S
  61.     IFNDEF I8086M
  62.     IFNDEF I8086C
  63.     IFNDEF I8086L
  64.         %OUT  NO MEMORY MODEL SPECIFIED
  65.         END
  66.     ENDIF
  67.     ENDIF
  68.     ENDIF
  69.     ENDIF
  70.  
  71. ;;;;; FORMAT FOR CRITICAL ERROR  HEADER BLOCK ;;;;;
  72. ;;;;; CERTAIN CHAR VARIABLES EXPANDED TO INT FOR PROPER ALLIGNMENT ;;;;;
  73. CERR        STRUC      ; critical error structure
  74. ceflag          db   ?  ; flag to indicate critical error 1 = yes
  75. cerrno          db   ?    ; critical error number  ; 2/16/91 changed to byte
  76. cerrtype      dw   ?    ; critical error type/action/drive, AX
  77. drive        db   ?  ; drive letter as a char
  78. read_wr        db   ?  ; read or write error 1 = write
  79. disk_area    db   ?  ; area of error, 0 = dos area, 1 = fat, 2 = dir, 3 = data
  80. resp_mask    db   ?  ; allowable responses (moot)
  81. exterr        db   ?  ; extended error number  DOS >= 3 2/16/91 changed to byte
  82. eclass        db   ?  ; error class
  83. action        db   ?  ; action recommendations
  84. locus        db   ?  ; locus
  85. nextdev       dd   ?  ; next device pointer
  86. attr          dw   ?  ; device attribute
  87. nxtfunc       dw   ?     ; pointer to next strategy function
  88. intfunc       dw   ?  ; pointer to interrupt function
  89. devname          db   8 dup(?)    ; device name
  90. dummy          db   ?  ; terminating null
  91. CERR    ENDS
  92.  
  93. ; SEE DOS TECHNICAL REFERENCE FOR EXPLANATION OF CODES
  94.  
  95.  
  96. ;;;;; BEGIN DATA SEGMENT ;;;;;  USING SIMPLIFIED SEGMENT DIRECTIVES
  97.  
  98.     .DATA            ; begin data segment
  99.     extrn __osmajor:byte    ; operating system version
  100. _criterrtrap     db 0         ; critical error flag 1=trapped, 0 = off
  101. ;;;;;     GLOBAL  ;;;;;
  102.     public _cerr          ; GLOBALS
  103. _cerr    CERR <>                 ; CRITICAL ERROR STRUCTURE BLOCK
  104.  
  105.     .DATA?            ; uninitialized data
  106. _oldint24vec      label  dword
  107. _oldint24off     dw ?         ; static vector to int 24 before trap
  108. _oldint24seg     dw ?         ;
  109.  
  110.  
  111. ; PROCEDURE CRITERR( ONOFF )
  112. ; SETS ALTERNATE CRITICAL ERROR HANDLER
  113. ; USAGE:    criterr( 1 ) to set, criterr( 0 ) to turn off
  114.  
  115.     .CODE            ; begin code segment
  116.  
  117. savds    dw    0        ; save proper data segment
  118.  
  119.     public _criterr
  120. ifdef SCODE
  121. _criterr    proc
  122. else
  123. _criterr    proc    far
  124. endif
  125.     push bp
  126.     mov bp, sp
  127.     push si
  128.     push di
  129.     mov ax, p[bp]        ; see if a 0 or 1 was passed
  130.     test ax, ax        ; non zero?
  131.     jne settrap             ; 1, so set trap
  132. removetrap:
  133.     cmp _criterrtrap, 1    ; see if installed
  134.     jne done            ; not installed, so return
  135.     push ds
  136.     lds dx, _oldint24vec    ; restore original int 24 vector
  137.      mov ax, 2524h
  138.      int 21h              ; dos set vector function
  139.      pop ds
  140.     mov _criterrtrap, 0    ; reset flag
  141.     xor ax, ax        ; set return code
  142.     jmp done
  143. settrap:
  144.     cmp _criterrtrap, 1    ; see if installed
  145.     je  done            ; yes, so return (AX = 1)
  146.     mov cs:savds, ds     ; move current data segment to savds
  147.      push    es
  148.      mov    ax,03524h    ; save old vector to int 24
  149.      int    021h
  150.     mov _oldint24off,bx
  151.     mov _oldint24seg,es
  152.     pop    es
  153.     push    ds
  154.     mov    dx, offset cs:int_service    ; load address of new routine
  155.     mov    ax,cs
  156.     mov    ds,ax
  157.     mov    ax,02524h         ; set it
  158.      int    021h
  159.     pop    ds
  160.     mov _criterrtrap, 1    ; set flag
  161.     xor ax, ax         ;set return code
  162.  
  163. done:
  164.     push ax                         ; save AX
  165.     ifdef LCODE
  166.     call far ptr _clrcriterr     ; reset values
  167.     else
  168.     call _clrcriterr
  169.     endif
  170.     pop ax
  171.     pop di
  172.     pop si
  173.     pop bp
  174.     ret            ; return to caller, return code in AX
  175.  
  176.  
  177. ;;;;; NEW CRITICAL ERROR HANDLER ;;;;;
  178. ;;;;; SEE DOS TECHNICAL REFERENCE ;;;;;
  179.  
  180. int_service:             ;int 24 trap goes here
  181.     push    bp
  182.     mov    bp,sp           ; set to critical stack frame
  183.     push    bx              ; all used registers except AX must be
  184.     push    cx              ; saved !!!!!
  185.     push    dx
  186.     push    si
  187.     push    di
  188.     push    ds
  189.     push    es
  190.     pushf
  191.     mov    ds,cs:savds     ; reset ds to program's ds
  192.     mov     bx, di          ; save DI
  193.     mov     di, offset _cerr  ; set di to point to structure cerr
  194.     mov     ceflag[di], 1   ; set ceflag 2/16/91
  195.     mov    cerrno[di], bl    ; move to cerrno -- move byte only 2/16/91
  196.     mov    cerrtype[di],ax    ; save error type/drive number
  197.     test    ax, 8000h    ; char or block device
  198.     mov    bx, ax
  199.     jnz    response    ; char device, so skip
  200.     add    bl, 'A'        ; add letter A
  201.     mov    drive[di], bl    ; move drive over
  202.     and    bh, 00000110b    ; leave only bits 1 and 2
  203.     shr    bh,1        ; shift it over 1
  204.     mov    disk_area[di], bh ; save area of error
  205.     mov    bh, ah
  206. response:                       ; determine response possibilities
  207.     and    bh, 1           ; 2/16/91 this block moved from prev para.
  208.     mov    read_wr[di], bh ; move read write flag
  209.     mov    bh, ah
  210.     and    bh, 00111000b    ; leave only bits 3-5
  211.     shr    bh,1
  212.     shr    bh,1
  213.     shr    bh,1        ; shift it over
  214.     mov    resp_mask[di],bh ; save response mask
  215. move_dev_header:        ; move device header block
  216.     push    ds              ; set up data registers
  217.     pop    es
  218.     mov    bx,[bp]        ; load bp to get segment for device header
  219.     mov    ds,bx           ; si contains offset of device header
  220.     mov    di,offset _cerr.nextdev    ; copy device header block
  221.     cld
  222.     mov    cx,9
  223.     rep     movsw            ; move 18 bytes of device header block
  224.     push    es
  225.     pop    ds              ; restore data registers
  226.  
  227.     ; now check for DOS version
  228.     xor    ax,ax        ; return code ignore for dos < 3
  229.     cmp    __osmajor,3    ; dos >= 3?
  230.     jl    doneint        ; no
  231.     ; prepare to get extended error
  232.         mov     bx, 0
  233.     mov    ah, 59h        ; get dos extended error
  234.     int    21h        ; call dos
  235.     mov    di, offset _cerr; set di to point to cerr structure
  236.     mov    exterr[di], al    ; error code  -- move byte only 2/16/91
  237.     mov    eclass[di], bh  ; error class
  238.     mov    action[di], bl  ; action
  239.     mov     locus[di],  ch  ; locus
  240.     mov     al, 3        ; return fail code
  241. doneint:
  242.     popf
  243.     pop    es
  244.     pop    ds
  245.     pop    di
  246.     pop    si
  247.     pop    dx
  248.     pop    cx
  249.     pop    bx
  250.     pop    bp        ; restore stack frame
  251.     iret            ; return from interrupt
  252. _criterr    endp
  253.  
  254. ;;;;;    FUNCTION TO CLEAR CRITICAL ERROR STATUS ;;;;;
  255.  
  256. ;;;;; USAGE:  clrcriterr()
  257.  
  258.     public _clrcriterr
  259. ifdef SCODE
  260. _clrcriterr    proc        ; function to clear critical error number
  261. else
  262. _clrcriterr    proc   far    ; function to clear critical error number
  263. endif
  264.  
  265.     push bp
  266.     mov bp,sp
  267.     push di
  268.     push ds
  269.     pop es
  270.     xor ax,ax        ; zero entire structure
  271.     mov di, offset _cerr
  272.     mov cx, size _cerr    ; get size of entire block
  273.     rep stosb
  274.     pop di
  275.     pop bp
  276.     ret
  277. _clrcriterr    endp
  278.  
  279. end
  280.  
  281. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  282. ; PROGRAM MODIFICATIONS
  283. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  284. ; MODIFIED 2/16/91 TO INCLUDE THE FOLLOWING
  285. ; STRUCTURE MEMBER ceflag ADDED
  286. ;  THIS WAS REQUIRED TO DETECT CRITICAL ERRORS, SINCE cerrno COULD HAVE
  287. ;  A VALUE OF 0 WHICH WOULD INDICATE A WRITE PROTECT ERROR.  ceflag WILL
  288. ;  BE SET IT THERE WAS A CRITICAL ERROR
  289. ; CALLS TO EXTERNAL FUNCTION _dos_exterr REMOVED
  290. ; STUCTURE MEMBERS cerrno AND exterr CHANGED TO BYTE SIZE
  291. ; STRUCTURE MEMBER pad REMOVED BECAUSE ABOVE MADE IT UNNECESSARY
  292. ; THE CODE WHICH SET THE read_wr STRUCTURE MEMBER WAS MOVED TO JUST
  293. ;  BELOW THE response: LABEL SINCE IT WAS NOT CORRECTLY LOCATED PREVIOUSLY
  294. ;  AND WOULD NEVER BE SET FOR NON-DISK ERRORS
  295. ; TEST